/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import java.sql.*;
import java.util.*;
import utils.*;

/**
 *
 * @author Felipe
 */
public class PesquisaDispData {

    public static int inserir(PesquisaDispDO pd, Transaction tr) throws SQLException {
        Connection c = tr.getConnection();
        String sql = "INSERT INTO " + Tabelas.PESQUISA_DISP + " (" + Tabelas.PESQUISA_DISP_user_id + "," + Tabelas.PESQUISA_DISP_pesquisa_id + ") VALUES (?,?);";
        PreparedStatement ps = c.prepareStatement(sql);
        ps.setInt(1, pd.getUser_id());
        ps.setInt(2, pd.getPesquisa_id());
        return ps.executeUpdate();
    } //inserir
    
    /* --------------------------------- */
    /* Incluído por Andrey em 10/11/2011 */
    /* --------------------------------- */
     public static LinkedList<PesquisaDispDO> buscar(int user_id, Transaction tr)
     throws Exception
     {
         LinkedList<PesquisaDispDO> lista = new LinkedList<PesquisaDispDO>();
         Connection con = tr.getConnection();
         String sql = "SELECT * FROM " + Tabelas.PESQUISA_DISP + " WHERE " + Tabelas.PESQUISA_DISP_user_id + " =?;";
         PreparedStatement ps = con.prepareStatement(sql);
         ps.setInt(1, user_id);
         ResultSet rs = ps.executeQuery();
         while(rs.next())
         {
            PesquisaDispDO p = new PesquisaDispDO();
            p.setUser_id(user_id);
            p.setPesquisa_id(rs.getInt(Tabelas.PESQUISA_DISP_pesquisa_id));
            lista.add(p);
         }
         return lista;
     }//buscar
}
